const http = {
	default: {
		baseURL: ''
	},
	get(url, data, header = { 'Content-Type': 'application/x-www-form-urlencoded' } || {}) {
		url = this.default.baseURL + url;

		// 返回一个promise对象
		return new Promise(function (resolve, reject) {
			// 发送请求
			uni.request({
				url,
				method: 'get',
				data: { ...data, token: uni.getStorageSync('token') } || { token: uni.getStorageSync('token') },
				header: header || {},
				success(data) {
					resolve(data);
				},
				fail(err) {
					reject(err);
				}
			});
		});
	},
	//
	post(url, data, header = { 'Content-Type': 'application/x-www-form-urlencoded' } || {}) {
		url = this.default.baseURL + url;

		// 返回一个promise对象
		return new Promise(function (resolve, reject) {
			// 发送请求
			uni.request({
				url,
				method: 'post',
				data: { ...data, token: uni.getStorageSync('token') } || { token: uni.getStorageSync('token') },
				header: header || {},
				success(data) {
					resolve(data);
				},
				fail(err) {
					reject(err);
				}
			});
		});
	}
};

export default http;
